<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/**
<span class='line'>  2</span>  * Constructs a new, empty matrix network layout. Layouts are not typically
<span class='line'>  3</span>  * constructed directly; instead, they are added to an existing panel via
<span class='line'>  4</span>  * {@link pv.Mark#add}.
<span class='line'>  5</span>  *
<span class='line'>  6</span>  * @class Implements a network visualization using a matrix view. This is, in
<span class='line'>  7</span>  * effect, a visualization of the graph's &lt;i>adjacency matrix&lt;/i>: the cell at
<span class='line'>  8</span>  * row &lt;i>i&lt;/i>, column &lt;i>j&lt;/i>, corresponds to the link from node &lt;i>i&lt;/i> to
<span class='line'>  9</span>  * node &lt;i>j&lt;/i>. The fill color of each cell is binary by default, and
<span class='line'> 10</span>  * corresponds to whether a link exists between the two nodes. If the underlying
<span class='line'> 11</span>  * graph has links with variable values, the &lt;tt>fillStyle&lt;/tt> property can be
<span class='line'> 12</span>  * substited to use an appropriate color function, such as {@link pv.ramp}.
<span class='line'> 13</span>  *
<span class='line'> 14</span>  * &lt;p>For undirected networks, the matrix is symmetric around the diagonal. For
<span class='line'> 15</span>  * directed networks, links in opposite directions can be rendered on opposite
<span class='line'> 16</span>  * sides of the diagonal using &lt;tt>directed(true)&lt;/tt>. The graph is assumed to
<span class='line'> 17</span>  * be undirected by default.
<span class='line'> 18</span>  *
<span class='line'> 19</span>  * &lt;p>The mark prototypes for this network layout are slightly different than
<span class='line'> 20</span>  * other implementations:&lt;ul>
<span class='line'> 21</span>  *
<span class='line'> 22</span>  * &lt;li>&lt;tt>node&lt;/tt> - unsupported; undefined. No mark is needed to visualize
<span class='line'> 23</span>  * nodes directly, as the nodes are implicit in the location (rows and columns)
<span class='line'> 24</span>  * of the links.
<span class='line'> 25</span>  *
<span class='line'> 26</span>  * &lt;p>&lt;li>&lt;tt>link&lt;/tt> - for rendering links; typically a {@link pv.Bar}. The
<span class='line'> 27</span>  * link mark is added directly to the layout, with the data property defined as
<span class='line'> 28</span>  * all possible pairs of nodes. Each pair is represented as a
<span class='line'> 29</span>  * {@link pv.Network.Layout.Link}, though the &lt;tt>linkValue&lt;/tt> attribute may
<span class='line'> 30</span>  * be 0 if no link exists in the graph.
<span class='line'> 31</span>  *
<span class='line'> 32</span>  * &lt;p>&lt;li>&lt;tt>label&lt;/tt> - for rendering node labels; typically a
<span class='line'> 33</span>  * {@link pv.Label}. The label mark is added directly to the layout, with the
<span class='line'> 34</span>  * data property defined via the layout's &lt;tt>nodes&lt;/tt> property; note,
<span class='line'> 35</span>  * however, that the nodes are duplicated so as to provide a label across the
<span class='line'> 36</span>  * top and down the side. Properties such as &lt;tt>strokeStyle&lt;/tt> and
<span class='line'> 37</span>  * &lt;tt>fillStyle&lt;/tt> can be overridden to compute properties from node data
<span class='line'> 38</span>  * dynamically.
<span class='line'> 39</span>  *
<span class='line'> 40</span>  * &lt;/ul>For more details on how to use this layout, see
<span class='line'> 41</span>  * {@link pv.Layout.Network}.
<span class='line'> 42</span>  *
<span class='line'> 43</span>  * @extends pv.Layout.Network
<span class='line'> 44</span>  */</span><span class="WHIT">
<span class='line'> 45</span> </span><span class="NAME">pv.Layout.Matrix</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">  </span><span class="NAME">pv.Layout.Network.call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">that</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">      </span><span class="NAME">n</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="COMM">// cached matrix size</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT">      </span><span class="NAME">dx</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="COMM">// cached cell width</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">      </span><span class="NAME">dy</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="COMM">// cached cell height</span><span class="WHIT">
<span class='line'> 51</span> </span><span class="WHIT">      </span><span class="NAME">labels</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="COMM">// cached labels (array of strings)</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">      </span><span class="NAME">pairs</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="COMM">// cached pairs (array of links)</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">      </span><span class="NAME">buildImplied</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">that.buildImplied</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 54</span> 
<span class='line'> 55</span> </span><span class="WHIT">  </span><span class="COMM">/** @private Cache layout state to optimize properties. */</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">  </span><span class="NAME">this.buildImplied</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">    </span><span class="NAME">buildImplied.call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">    </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.nodes.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">    </span><span class="NAME">dx</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.width</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">    </span><span class="NAME">dy</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.height</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">    </span><span class="NAME">labels</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.$matrix.labels</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">    </span><span class="NAME">pairs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.$matrix.pairs</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 64</span> 
<span class='line'> 65</span> </span><span class="WHIT">  </span><span class="COMM">/* Links are all pairs of nodes. */</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">  </span><span class="NAME">this.link</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">data</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">left</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">dx</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.index</span><span class="WHIT"> </span><span class="PUNC">%</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">top</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">dy</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">Math.floor</span><span class="PUNC">(</span><span class="NAME">this.index</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">width</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">dx</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">height</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">dy</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">lineWidth</span><span class="PUNC">(</span><span class="NUMB">1.5</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">strokeStyle</span><span class="PUNC">(</span><span class="STRN">"#fff"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">fillStyle</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">l</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">l.linkValue</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">"#555"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"#eee"</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">parent</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 76</span> 
<span class='line'> 77</span> </span><span class="WHIT">  </span><span class="COMM">/* No special add for links! */</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">  </span><span class="KEYW">delete</span><span class="WHIT"> </span><span class="NAME">this.link.add</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 79</span> 
<span class='line'> 80</span> </span><span class="WHIT">  </span><span class="COMM">/* Labels are duplicated for top & left. */</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT">  </span><span class="NAME">this.label</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">data</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">labels</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">left</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.index</span><span class="WHIT"> </span><span class="PUNC">&</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">dx</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">this.index</span><span class="WHIT"> </span><span class="PUNC">>></span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">.</span><span class="NUMB">5</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">top</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.index</span><span class="WHIT"> </span><span class="PUNC">&</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">dy</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">this.index</span><span class="WHIT"> </span><span class="PUNC">>></span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">.</span><span class="NUMB">5</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">textMargin</span><span class="PUNC">(</span><span class="NUMB">4</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">textAlign</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.index</span><span class="WHIT"> </span><span class="PUNC">&</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">"left"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"right"</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">      </span><span class="PUNC">.</span><span class="NAME">textAngle</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this.index</span><span class="WHIT"> </span><span class="PUNC">&</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="NAME">Math.PI</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NUMB">2</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 88</span> 
<span class='line'> 89</span> </span><span class="WHIT">  </span><span class="COMM">/* The node mark is unused. */</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">  </span><span class="KEYW">delete</span><span class="WHIT"> </span><span class="NAME">this.node</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 92</span> 
<span class='line'> 93</span> </span><span class="NAME">pv.Layout.Matrix.prototype</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.extend</span><span class="PUNC">(</span><span class="NAME">pv.Layout.Network</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">    </span><span class="PUNC">.</span><span class="NAME">property</span><span class="PUNC">(</span><span class="STRN">"directed"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">Boolean</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 95</span> 
<span class='line'> 96</span> </span><span class="COMM">/**
<span class='line'> 97</span>  * Whether this matrix visualization is directed (bidirectional). By default,
<span class='line'> 98</span>  * the graph is assumed to be undirected, such that the visualization is
<span class='line'> 99</span>  * symmetric across the matrix diagonal. If the network is directed, then
<span class='line'>100</span>  * forward links are drawn above the diagonal, while reverse links are drawn
<span class='line'>101</span>  * below.
<span class='line'>102</span>  *
<span class='line'>103</span>  * @type boolean
<span class='line'>104</span>  * @name pv.Layout.Matrix.prototype.directed
<span class='line'>105</span>  */</span><span class="WHIT">
<span class='line'>106</span> 
<span class='line'>107</span> </span><span class="COMM">/**
<span class='line'>108</span>  * Specifies an optional sort function. The sort function follows the same
<span class='line'>109</span>  * comparator contract required by {@link pv.Dom.Node#sort}. Specifying a sort
<span class='line'>110</span>  * function provides an alternative to sort the nodes as they are specified by
<span class='line'>111</span>  * the &lt;tt>nodes&lt;/tt> property; the main advantage of doing this is that the
<span class='line'>112</span>  * comparator function can access implicit fields populated by the network
<span class='line'>113</span>  * layout, such as the &lt;tt>linkDegree&lt;/tt>.
<span class='line'>114</span>  *
<span class='line'>115</span>  * &lt;p>Note that matrix visualizations are particularly sensitive to order. This
<span class='line'>116</span>  * is referred to as the seriation problem, and many different techniques exist
<span class='line'>117</span>  * to find good node orders that emphasize clusters, such as spectral layout and
<span class='line'>118</span>  * simulated annealing.
<span class='line'>119</span>  *
<span class='line'>120</span>  * @param {function} f comparator function for nodes.
<span class='line'>121</span>  * @returns {pv.Layout.Matrix} this.
<span class='line'>122</span>  */</span><span class="WHIT">
<span class='line'>123</span> </span><span class="NAME">pv.Layout.Matrix.prototype.sort</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">f</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT">  </span><span class="NAME">this.$sort</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">f</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>125</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>126</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>127</span> 
<span class='line'>128</span> </span><span class="COMM">/** @private */</span><span class="WHIT">
<span class='line'>129</span> </span><span class="NAME">pv.Layout.Matrix.prototype.buildImplied</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">s</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">pv.Layout.Network.prototype.buildImplied.call</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">s</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>131</span> 
<span class='line'>132</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nodes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.nodes</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT">      </span><span class="NAME">links</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">s.links</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>134</span> </span><span class="WHIT">      </span><span class="NAME">sort</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.$sort</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT">      </span><span class="NAME">n</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">nodes.length</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT">      </span><span class="NAME">index</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">pv.range</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT">      </span><span class="NAME">labels</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>138</span> </span><span class="WHIT">      </span><span class="NAME">pairs</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT">      </span><span class="NAME">map</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>140</span> 
<span class='line'>141</span> </span><span class="WHIT">  </span><span class="NAME">s.$matrix</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="NAME">labels</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">labels</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">pairs</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>142</span> 
<span class='line'>143</span> </span><span class="WHIT">  </span><span class="COMM">/* Sort the nodes. */</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">sort</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">index.sort</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">a</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">sort</span><span class="PUNC">(</span><span class="NAME">nodes</span><span class="PUNC">[</span><span class="NAME">a</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">nodes</span><span class="PUNC">[</span><span class="NAME">b</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>145</span> 
<span class='line'>146</span> </span><span class="WHIT">  </span><span class="COMM">/* Create pairs. */</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">j</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">j</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>149</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">index</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT">          </span><span class="NAME">b</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">index</span><span class="PUNC">[</span><span class="NAME">j</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>151</span> </span><span class="WHIT">          </span><span class="NAME">p</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT">            </span><span class="NAME">row</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT">            </span><span class="NAME">col</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">j</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT">            </span><span class="NAME">sourceNode</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">nodes</span><span class="PUNC">[</span><span class="NAME">a</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>155</span> </span><span class="WHIT">            </span><span class="NAME">targetNode</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">nodes</span><span class="PUNC">[</span><span class="NAME">b</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT">            </span><span class="NAME">linkValue</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="WHIT">
<span class='line'>157</span> </span><span class="WHIT">          </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT">      </span><span class="NAME">pairs.push</span><span class="PUNC">(</span><span class="NAME">map</span><span class="PUNC">[</span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"."</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">b</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">p</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>160</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>161</span> 
<span class='line'>162</span> </span><span class="WHIT">  </span><span class="COMM">/* Create labels. */</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">n</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">a</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">index</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT">    </span><span class="NAME">labels.push</span><span class="PUNC">(</span><span class="NAME">nodes</span><span class="PUNC">[</span><span class="NAME">a</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">nodes</span><span class="PUNC">[</span><span class="NAME">a</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>167</span> 
<span class='line'>168</span> </span><span class="WHIT">  </span><span class="COMM">/* Accumulate link values. */</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">  </span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">links.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">l</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">links</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT">        </span><span class="NAME">source</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">l.sourceNode.index</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT">        </span><span class="NAME">target</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">l.targetNode.index</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>173</span> </span><span class="WHIT">        </span><span class="NAME">value</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">l.linkValue</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>174</span> </span><span class="WHIT">    </span><span class="NAME">map</span><span class="PUNC">[</span><span class="NAME">source</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"."</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">target</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">linkValue</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>175</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">s.directed</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="NAME">map</span><span class="PUNC">[</span><span class="NAME">target</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">"."</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">source</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">linkValue</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>176</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>177</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>178</span> </span></pre></body></html>